home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / standard / mp.z / mp
Encoding:
Text File  |  1998-10-30  |  43.1 KB  |  925 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  71.  
  72.  
  73.  
  74. NNNNAAAAMMMMEEEE
  75.      mp: mp_block, mp_blocktime, mp_create, mp_destroy, mp_my_threadnum,
  76.      mp_numthreads, mp_set_numthreads, mp_setup, mp_unblock, mp_setlock,
  77.      mp_suggested_numthreads, mp_unsetlock, mp_barrier, mp_in_doacross_loop,
  78.      mp_set_slave_stacksize - C multiprocessing utility functions
  79.  
  80. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  81.      vvvvooooiiiidddd mmmmpppp____bbbblllloooocccckkkk(((())))
  82.  
  83.      vvvvooooiiiidddd mmmmpppp____uuuunnnnbbbblllloooocccckkkk(((())))
  84.  
  85.      vvvvooooiiiidddd mmmmpppp____bbbblllloooocccckkkkttttiiiimmmmeeee((((iiiitttteeeerrrrssss))))
  86.      iiiinnnntttt iiiitttteeeerrrrssss
  87.  
  88.      vvvvooooiiiidddd mmmmpppp____sssseeeettttuuuupppp(((())))
  89.  
  90.      vvvvooooiiiidddd mmmmpppp____ccccrrrreeeeaaaatttteeee((((nnnnuuuummmm))))
  91.      iiiinnnntttt nnnnuuuummmm
  92.  
  93.      vvvvooooiiiidddd mmmmpppp____ddddeeeessssttttrrrrooooyyyy(((())))
  94.  
  95.      iiiinnnntttt mmmmpppp____nnnnuuuummmmtttthhhhrrrreeeeaaaaddddssss(((())))
  96.  
  97.      vvvvooooiiiidddd mmmmpppp____sssseeeetttt____nnnnuuuummmmtttthhhhrrrreeeeaaaaddddssss((((nnnnuuuummmm))))
  98.      iiiinnnntttt nnnnuuuummmm
  99.  
  100.      iiiinnnntttt mmmmpppp____mmmmyyyy____tttthhhhrrrreeeeaaaaddddnnnnuuuummmm(((())))
  101.  
  102.      iiiinnnntttt mmmmpppp____iiiissss____mmmmaaaasssstttteeeerrrr(((())))
  103.  
  104.      vvvvooooiiiidddd mmmmpppp____sssseeeettttlllloooocccckkkk(((())))
  105.  
  106.      vvvvooooiiiidddd mmmmpppp____uuuunnnnsssseeeettttlllloooocccckkkk(((())))
  107.  
  108.      vvvvooooiiiidddd mmmmpppp____bbbbaaaarrrrrrrriiiieeeerrrr(((())))
  109.  
  110.      iiiinnnntttt mmmmpppp____iiiinnnn____ddddooooaaaaccccrrrroooossssssss____lllloooooooopppp(((())))
  111.  
  112.      vvvvooooiiiidddd mmmmpppp____sssseeeetttt____ssssllllaaaavvvveeee____ssssttttaaaacccckkkkssssiiiizzzzeeee((((ssssiiiizzzzeeee))))
  113.      iiiinnnntttt ssssiiiizzzzeeee
  114.  
  115.      uuuunnnnssssiiiiggggnnnneeeedddd iiiinnnntttt mmmmpppp____ssssuuuuggggggggeeeesssstttteeeedddd____nnnnuuuummmmtttthhhhrrrreeeeaaaaddddssss((((nnnnuuuummmm))))
  116.      uuuunnnnssssiiiiggggnnnneeeedddd iiiinnnntttt nnnnuuuummmm
  117.  
  118.  
  119. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  120.      These routines give some measure of control over the parallelism used in
  121.      C programs.  They should not be needed by most users, but will help to
  122.      tune specific applications.
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  137.  
  138.  
  139.  
  140.      _m_p__b_l_o_c_k puts all slave threads to sleep via _b_l_o_c_k_p_r_o_c(2).  This frees
  141.      the processors for use by other jobs.  This is useful if it is known that
  142.      the slaves will not be needed for some time, and the machine is being
  143.      shared by several users.  Calls to _m_p__b_l_o_c_k may not be nested; a warning
  144.      is issued if an attempt to do so is made.
  145.  
  146.      _m_p__u_n_b_l_o_c_k wakes up the slave threads that were previously blocked via
  147.      _m_p__b_l_o_c_k.  It is an error to unblock threads that are not currently
  148.      blocked; a warning is issued if an attempt is made to do so.
  149.  
  150.      It is not necessary to explicitly call _m_p__u_n_b_l_o_c_k.  When a parallel
  151.      region is entered, a check is made, and if the slaves are currently
  152.      blocked, a call is made to _m_p__u_n_b_l_o_c_k automatically.
  153.  
  154.      _m_p__b_l_o_c_k_t_i_m_e controls the amount of time a slave thread waits for work
  155.      before giving up.  When enough time has elapsed, the slave thread blocks
  156.      itself.  This automatic blocking is independent of the user level
  157.      blocking provided by the _m_p__b_l_o_c_k/_m_p__u_n_b_l_o_c_k calls.  Slave threads that
  158.      have blocked themselves will be automatically unblocked upon entering a
  159.      parallel region.  The argument to _m_p__b_l_o_c_k_t_i_m_e is the number of times to
  160.      spin in the wait loop.  By default, it is set to 10,000,000.  This takes
  161.      about .25 seconds on a 200MHz processor.  As a special case, an argument
  162.      of 0 disables the automatic blocking, and the slaves will spin wait
  163.      without limit.  The environment variable _M_P__B_L_O_C_K_T_I_M_E may be set to an
  164.      integer value.  It acts like an implicit call to _m_p__b_l_o_c_k_t_i_m_e during
  165.      program startup.
  166.  
  167.      _m_p__d_e_s_t_r_o_y deletes the slave threads.  They are stopped by forcing them
  168.      to call _e_x_i_t(2).  In general, doing this is discouraged.  _m_p__b_l_o_c_k can be
  169.      used in most cases.
  170.  
  171.      _m_p__c_r_e_a_t_e creates and initializes threads.  It creates enough threads so
  172.      that the total number is equal to the argument.  Since the calling thread
  173.      already counts as one, _m_p__c_r_e_a_t_e will create one less than its argument
  174.      in new slave threads.
  175.  
  176.      _m_p__s_e_t_u_p also creates and initializes threads.  It takes no arguments.
  177.      It simply calls _m_p__c_r_e_a_t_e using the current default number of threads.
  178.      Normally the default number is equal to the number of cpu's currently on
  179.      the machine.  If the user has not called either of the thread creation
  180.      routines already, then _m_p__s_e_t_u_p is invoked automatically when the first
  181.      parallel region is entered.  If the environment variable _M_P__S_E_T_U_P is set,
  182.      then _m_p__s_e_t_u_p is called during initialization, before any user code is
  183.      executed.
  184.  
  185.      _m_p__n_u_m_t_h_r_e_a_d_s returns the number of threads that would participate in an
  186.      immediately following parallel region.  If the threads have already been
  187.      created, then it returns the current number of threads.  If the threads
  188.      have not been created, then it returns the current default number of
  189.      threads.  The count includes the master thread. Knowing this count can be
  190.      useful in optimizing certain kinds of parallel loops by hand, but this
  191.      function has the side-effect of freezing the number of threads to the
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  203.  
  204.  
  205.  
  206.      returned value.  As a result, this routine should be used sparingly. To
  207.      determine the number of threads without this side-effect, see the
  208.      description of _m_p__s_u_g_g_e_s_t_e_d__n_u_m_t_h_r_e_a_d_s below.
  209.  
  210.      _m_p__s_e_t__n_u_m_t_h_r_e_a_d_s sets the current default number of threads to the
  211.      specified value.  Note that this call does not directly create the
  212.      threads, it only specifies the number that a subsequent _m_p__s_e_t_u_p call
  213.      should use.  If the environment variable _M_P__S_E_T__N_U_M_T_H_R_E_A_D_S is set, it
  214.      acts like an implicit call to _m_p__s_e_t__n_u_m_t_h_r_e_a_d_s during program startup.
  215.      For convenience when operating among several machines with different
  216.      numbers of cpus, _M_P__S_E_T__N_U_M_T_H_R_E_A_D_S may be set to an expression involving
  217.      integer literals, the binary operators + and -, the binary functions min
  218.      and max, and the special symbolic value _A_L_L which stands for "the total
  219.      number of available cpus on the current machine."  Thus, something simple
  220.      like
  221.                  setenv MP_SET_NUMTHREADS 7
  222.      would set the number of threads to seven.  This may be a fine choice on
  223.      an 8 cpu machine, but would be very bad on a 4 cpu machine.  Instead, use
  224.      something like
  225.                  setenv MP_SET_NUMTHREADS "max(1,all-1)"
  226.      which sets the number of threads to be one less than the number of cpus
  227.      on the current machine (but always at least one).  If your configuration
  228.      includes some machines with large numbers of cpus, setting an upper bound
  229.      is a good idea.  Something like:
  230.                  setenv MP_SET_NUMTHREADS "min(all,4)"
  231.      will request (no more than) 4 cpus.
  232.  
  233.      For compatibility with earlier releases, _N_U_M__T_H_R_E_A_D_S is supported as a
  234.      synonym for _M_P__S_E_T__N_U_M_T_H_R_E_A_D_S.
  235.  
  236.      _m_p__m_y__t_h_r_e_a_d_n_u_m returns an integer between 0 and _n-1 where _n is the value
  237.      returned by _m_p__n_u_m_t_h_r_e_a_d_s.  The master process is always thread 0.  This
  238.      is occasionally useful for optimizing certain kinds of loops by hand.
  239.  
  240.      _m_p__i_s__m_a_s_t_e_r returns 1 if called by the master process, 0 otherwise.
  241.  
  242.      _m_p__s_e_t_l_o_c_k provides convenient (though limited) access to the locking
  243.      routines.  The convenience is that no set up need be done; it may be
  244.      called directly without any preliminaries.  The limitation is that there
  245.      is only one lock.  It is analogous to the _u_s_s_e_t_l_o_c_k(3P) routine, but it
  246.      takes no arguments and does not return a value.  This is useful for
  247.      serializing access to shared variables (e.g.  counters) in a parallel
  248.      region.  Note that it will frequently be necessary to declare those
  249.      variables as _v_o_l_a_t_i_l_e to ensure that the optimizer does not assign them
  250.      to a register.
  251.  
  252.      _m_p__u_n_s_e_t_l_o_c_k is the companion routine for _m_p__s_e_t_l_o_c_k.  It also takes no
  253.      arguments and does not return a value.
  254.  
  255.      _m_p__b_a_r_r_i_e_r provides a simple interface to a single _b_a_r_r_i_e_r(3P).  It may
  256.      be used inside a parallel loop to force a barrier synchronization to
  257.      occur among the parallel threads.  The routine takes no arguments,
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  269.  
  270.  
  271.  
  272.      returns no value, and does not require any initialization.
  273.  
  274.      _m_p__i_n__d_o_a_c_r_o_s_s__l_o_o_p answers the question "am I currently executing inside
  275.      a parallel loop."  This is needful in certain rare situations where you
  276.      have an external routine that can be called both from inside a parallel
  277.      loop and also from outside a parallel loop, and the routine must do
  278.      different things depending on whether it is being called in parallel or
  279.      not.
  280.  
  281.      _m_p__s_e_t__s_l_a_v_e__s_t_a_c_k_s_i_z_e sets the stacksize (in bytes) to be used by the
  282.      slave processes when they are created (via _s_p_r_o_c_s_p(2)).  The default size
  283.      is 16MB.  Note that slave processes only allocate their local data onto
  284.      their stack, shared data (even if allocated on the master's stack) is not
  285.      counted.
  286.  
  287.      _m_p__s_u_g_g_e_s_t_e_d__n_u_m_t_h_r_e_a_d_s uses the supplied value as a hint about how many
  288.      threads to use in subsequent parallel regions, and returns the previous
  289.      value of the number of threads to be employed in parallel regions. It
  290.      does not affect currently executing parallel regions, if any. The
  291.      implementation may ignore this hint depending on factors such as overall
  292.      system load.  This routine may also be called with the value 0, in which
  293.      case it simply returns the number of threads to be employed in parallel
  294.      regions without the side-effect present in _m_p__n_u_m_t_h_r_e_a_d_s.
  295.  
  296.      PPPPrrrraaaaggggmmmmaaaassss oooorrrr ddddiiiirrrreeeeccccttttiiiivvvveeeessss
  297.  
  298.      The MIPSpro C (and C++) compiler allows you to apply the capabilities of
  299.      a Silicon Graphics multiprocessor computer to the execution of a single
  300.      job. By coding a few simple directives, the compiler splits the job into
  301.      concurrently executing pieces, thereby decreasing the wall-clock run time
  302.      of the job.
  303.  
  304.      Directives enable, disable, or modify a feature of the compiler.
  305.      Essentially, directives are command line options specified within the
  306.      input file instead of on the command line. Unlike command line options,
  307.      directives have no default setting. To invoke a directive, you must
  308.      either toggle it on or set a desired value for its level.  The following
  309.      directives can be used in C (and C++) programs when compiled with the ----mmmmpppp
  310.      option.
  311.  
  312.  
  313.      ####pppprrrraaaaggggmmmmaaaa ppppaaaarrrraaaalllllllleeeellll
  314.  
  315.          This pragma denotes the start of a parallel region. The syntax for
  316.          this pragma has a number of modifiers, but to run a single loop in
  317.          parallel, the only modifiers you usually use are sssshhhhaaaarrrreeeedddd,,,, and llllooooccccaaaallll....
  318.          These options tell the multiprocessing compiler which variables to
  319.          share between all threads of execution and which variables should be
  320.          treated as local.
  321.  
  322.          In C, the code that comprises the parallel region is delimited by
  323.          curly braces ({ }) and immediately follows the parallel pragma and
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  335.  
  336.  
  337.  
  338.          its modifiers.
  339.  
  340.          The syntax for this pragma is:
  341.  
  342.          ####pppprrrraaaaggggmmmmaaaa ppppaaaarrrraaaalllllllleeeellll sssshhhhaaaarrrreeeedddd ((((vvvvaaaarrrriiiiaaaabbbblllleeeessss))))
  343.          ####pppprrrraaaaggggmmmmaaaa llllooooccccaaaallll ((((vvvvaaaarrrriiiiaaaabbbblllleeeessss)))) ooooppppttttiiiioooonnnnaaaallll mmmmooooddddiiiiffffiiiieeeerrrrssss
  344.          {{{{ccccooooddddeeee}}}}
  345.  
  346.          The parallel pragma has four modifiers: sssshhhhaaaarrrreeeedddd,,,, llllooooccccaaaallll,,,, iiiiffff,,,, and
  347.          nnnnuuuummmmtttthhhhrrrreeeeaaaaddddssss....
  348.  
  349.          Their definitions ares:
  350.  
  351.              sssshhhhaaaarrrreeeedddd (((( vvvvaaaarrrriiiiaaaabbbblllleeee____nnnnaaaammmmeeeessss ))))
  352.  
  353.              Tells the multiprocessing C compiler the names of all the
  354.              variables that the threads must share.
  355.  
  356.              llllooooccccaaaallll (((( vvvvaaaarrrriiiiaaaabbbblllleeee____nnnnaaaammmmeeeessss ))))
  357.  
  358.              Tells the multiprocessing C compiler the names of all the
  359.              variables that must be private to each thread. (When PCA sets up
  360.              a parallel region, it does this for you.)
  361.  
  362.              iiiiffff (((( iiiinnnntttteeeeggggeeeerrrr____vvvvaaaalllluuuueeeedddd____eeeexxxxpppprrrr ))))
  363.  
  364.              Lets you set up a condition that is evaluated at run time to
  365.              determine whether or not to run the statement(s) serially or in
  366.              parallel. At compile time, it is not always possible to judge how
  367.              much work a parallel region does (for example, loop indices are
  368.              often calculated from data supplied at run time). Avoid running
  369.              trivial amounts of code in parallel because you cannot make up
  370.              the overhead associated with running code in parallel. PCA will
  371.              also generate this condition as appropriate.  If the iiiiffff condition
  372.              is false (equal to zero), then the statement(s) runs serially.
  373.              Otherwise, the statement(s) run in parallel.
  374.  
  375.              nnnnuuuummmmtttthhhhrrrreeeeaaaaddddssss((((eeeexxxxpppprrrr))))
  376.  
  377.              Tells the multiprocessing C compiler the number of available
  378.              threads to use when running this region in parallel. (The default
  379.              is all the available threads.)
  380.  
  381.              In general, you should never have more threads of execution than
  382.              you have processors, and you should specify  numthreads with the
  383.              MMMMPPPP____SSSSEEEETTTT____NNNNUUUUMMMMTTTTHHHHRRRREEEEAAAADDDDSSSS environmental variable at run time If you want
  384.              to run a loop in parallel while you run some other code, you can
  385.              use this option to tell the multiprocessing C compiler to use
  386.              only some of the available threads.
  387.  
  388.              The expression eeeexxxxpppprrrr should evaluate to a positive integer.
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  401.  
  402.  
  403.  
  404.              For example, to start a parallel region in which to run the
  405.              following code in parallel:
  406.  
  407.              for (idx=n; idx; idx--) {
  408.  
  409.                 a[idx] = b[idx] + c[idx];
  410.  
  411.              }
  412.  
  413.              you must write:
  414.  
  415.              #pragma parallel shared( a, b, c ) shared(n) local( idx )
  416.  
  417.              or:
  418.  
  419.              #pragma parallel
  420.  
  421.              #pragma shared( a, b, c )
  422.  
  423.              #pragma shared(n)
  424.  
  425.              #pragma local(idx)
  426.  
  427.              before the statement or compound statement (code in curly braces,
  428.              { }) that comprises the parallel region.
  429.  
  430.              Any code within a parallel region but not within any of the
  431.              explicit parallel constructs ( ppppffffoooorrrr,,,, iiiinnnnddddeeeeppppeeeennnnddddeeeennnntttt,,,, oooonnnneeee pppprrrroooocccceeeessssssssoooorrrr,,,,
  432.              and ccccrrrriiiittttiiiiccccaaaallll ) is termed local code. Local code typically
  433.              modifies only local data and is run by all threads.
  434.  
  435.  
  436.      ####pppprrrraaaaggggmmmmaaaa ppppffffoooorrrr
  437.  
  438.          The ppppffffoooorrrr is contained within a parallel region.  Use ####pppprrrraaaaggggmmmmaaaa ppppffffoooorrrr to
  439.          run a for loop in parallel only if the loop meets all of these
  440.          conditions:
  441.  
  442.              All the values of the index variable can be computed
  443.              independently of the iterations.
  444.  
  445.              All iterations are independent of each other - that is, data used
  446.              in one iteration does not depend on data created by another
  447.              iteration. A quick test for independence: if the loop can be run
  448.              backwards, then chances are good the iterations are independent.
  449.  
  450.              The loop control variable cannot be a field within a
  451.              class/struct/union or an array element.
  452.  
  453.              The number of times the loop must be executed is determined once,
  454.              upon entry to the loop, and is based on the loop initialization,
  455.              loop test, and loop increment statements.
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  467.  
  468.  
  469.  
  470.              If the number of times the loop is actually executed is different
  471.              from what is computed above, the results are unpredictable. This
  472.              can happen if the loop test and increment change during the
  473.              execution of the loop, or if there is an early exit from within
  474.              the for loop. An early exit or a change to the loop test and
  475.              increment during execution may have serious performance
  476.              implications.
  477.  
  478.              The test or the increment should not contain expressions with
  479.              side effects.
  480.  
  481.              The cccchhhhuuuunnnnkkkkssssiiiizzzzeeee,,,, if specified, is computed before the loop is
  482.              executed, and the behavior is unpredictable if its value changes
  483.              within the loop.
  484.  
  485.              If you are writing a ppppffffoooorrrr loop for the multiprocessing C++
  486.              compiler, the index variable _i can be declared within the for
  487.              statement via
  488.  
  489.              int i = 0;
  490.  
  491.              The draft for the C++ standard states that the scope of the index
  492.              variable declared in a for statement extends to the end of the
  493.              for statement, as in this example:
  494.  
  495.              #pragma pfor for (int i = 0, ...)
  496.  
  497.              The C++ compiler doesn't enforce this; in fact, with this
  498.              compiler the scope extends to the end of the enclosing block. Use
  499.              care when writing code so that the subsequent change in scope
  500.              rules for _i (in later compiler releases) do not affect the user
  501.              code.
  502.  
  503.          If the code after a ppppffffoooorrrr is not dependent on the calculations made in
  504.          the ppppffffoooorrrr loop, there is no reason to synchronize the threads of
  505.          execution before they continue. So, if one thread from the ppppffffoooorrrr
  506.          finishes early, it can go on to execute the serial code without
  507.          waiting for the other threads to finish their part of the loop.
  508.  
  509.          The ####pppprrrraaaaggggmmmmaaaa ppppffffoooorrrr directive takes several modifiers; the only one that
  510.          is required is iiiitttteeeerrrraaaatttteeee.... ####pppprrrraaaaggggmmmmaaaa ppppffffoooorrrr tells the compiler that each
  511.          iteration of the loop is unique.  It also partitions the iterations
  512.          among the threads for execution.
  513.  
  514.          The syntax for ####pppprrrraaaaggggmmmmaaaa ppppffffoooorrrr is:
  515.  
  516.          ####pppprrrraaaaggggmmmmaaaa ppppffffoooorrrr iiiitttteeeerrrraaaatttteeee (((( )))) ooooppppttttiiiioooonnnnaaaallll____mmmmooooddddiiiiffffiiiieeeerrrrssss
  517.          ffffoooorrrr ............
  518.             {{{{ ccccooooddddeeee ............ }}}}
  519.  
  520.          The ppppffffoooorrrr pragma has several modifiers. Their syntax is:
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  533.  
  534.  
  535.  
  536.          iiiitttteeeerrrraaaatttteeee ((((iiiinnnnddddeeeexxxx vvvvaaaarrrriiiiaaaabbbblllleeee====eeeexxxxpppprrrr1111;;;; eeeexxxxpppprrrr2222;;;; eeeexxxxpppprrrr3333 ))))
  537.          llllooooccccaaaallll((((vvvvaaaarrrriiiiaaaabbbblllleeee lllliiiisssstttt))))
  538.          llllaaaassssttttllllooooccccaaaallll ((((vvvvaaaarrrriiiiaaaabbbblllleeee lllliiiisssstttt))))
  539.          rrrreeeedddduuuuccccttttiiiioooonnnn ((((vvvvaaaarrrriiiiaaaabbbblllleeee lllliiiisssstttt))))
  540.          aaaaffffffffiiiinnnniiiittttyyyy ((((vvvvaaaarrrriiiiaaaabbbblllleeee)))) ==== tttthhhhrrrreeeeaaaadddd ((((eeeexxxxpppprrrreeeessssssssiiiioooonnnn))))
  541.          sssscccchhhheeeeddddttttyyyyppppeeee ((((ttttyyyyppppeeee))))
  542.          cccchhhhuuuunnnnkkkkssssiiiizzzzeeee ((((eeeexxxxpppprrrr))))
  543.  
  544.          Where:
  545.  
  546.              iiiitttteeeerrrraaaatttteeee ((((iiiinnnnddddeeeexxxx vvvvaaaarrrriiiiaaaabbbblllleeee====eeeexxxxpppprrrr1111;;;; eeeexxxxpppprrrr2222;;;; eeeexxxxpppprrrr3333 ))))
  547.  
  548.              Gives the multiprocessing C compiler the information it needs to
  549.              identify the unique iterations of the loop and partition them to
  550.              particular threads of execution.
  551.  
  552.                  iiiinnnnddddeeeexxxx vvvvaaaarrrriiiiaaaabbbblllleeee is the index variable of the for loop you want
  553.                  to run in parallel.
  554.  
  555.                  eeeexxxxpppprrrr1111 is the starting value for the loop index.
  556.  
  557.                  eeeexxxxpppprrrr2222 is the number of iterations for the loop you want to
  558.                  run in parallel.
  559.  
  560.                  eeeexxxxpppprrrr3333 is the increment of the for loop you want to run in
  561.                  parallel.
  562.  
  563.              llllooooccccaaaallll ((((vvvvaaaarrrriiiiaaaabbbblllleeee lllliiiisssstttt))))
  564.  
  565.              Specifies variables that are local to each process. If a variable
  566.              is declared as local, each iteration of the loop is given its own
  567.              uninitialized copy of the variable. You can declare a variable as
  568.              local if its value does not depend on any other iteration of the
  569.              loop and if its value is used only within a single iteration. In
  570.              effect the local variable is just temporary; a new copy can be
  571.              created in each loop iteration without changing the final answer.
  572.  
  573.              llllaaaassssttttllllooooccccaaaallll ((((vvvvaaaarrrriiiiaaaabbbblllleeee lllliiiisssstttt))))
  574.  
  575.              Specifies variables that are local to each process. Unlike with
  576.              the llllooooccccaaaallll clause, the compiler saves only the value of the
  577.              logically last iteration of the loop when it exits.
  578.  
  579.              rrrreeeedddduuuuccccttttiiiioooonnnn ((((vvvvaaaarrrriiiiaaaabbbblllleeee lllliiiisssstttt))))
  580.  
  581.              Specifies variables involved in a reduction operation. In a
  582.              reduction operation, the compiler keeps local copies of the
  583.              variables and combines them when it exits the loop. An element of
  584.              the reduction list must be an individual variable (also called a
  585.              scalar variable) and cannot be an array or struct. However, it
  586.              can be an individual element of an array. When the reduction
  587.              modifier is used, it appears in the list with the correct
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  599.  
  600.  
  601.  
  602.              subscripts.
  603.  
  604.              One element of an array can be used in a reduction operation,
  605.              while other elements of the array are used in other ways. To
  606.              allow for this, if an element of an array appears in the
  607.              reduction list, the entire array can also appear in the share
  608.              list.
  609.  
  610.              The two types of reductions supported are _s_u_m(+) and _p_r_o_d_u_c_t(*).
  611.  
  612.              The compiler confirms that the reduction expression is legal by
  613.              making some simple checks. The compiler does not, however, check
  614.              all statements in the do loop for illegal reductions. You must
  615.              ensure that the reduction variable is used correctly in a
  616.              reduction operation.
  617.  
  618.              aaaaffffffffiiiinnnniiiittttyyyy ((((vvvvaaaarrrriiiiaaaabbbblllleeee)))) ==== tttthhhhrrrreeeeaaaadddd ((((eeeexxxxpppprrrreeeessssssssiiiioooonnnn))))
  619.  
  620.              The effect of thread-affinity is to execute iteration "i" on the
  621.              thread number given by the user-supplied expression (modulo the
  622.              number of threads). Since the threads may need to evaluate this
  623.              expression in each iteration of the loop, the variables used in
  624.              the expression (other than the loop induction variable) must be
  625.              declared shared and must not be modified during the execution of
  626.              the loop. Violating these rules may lead to incorrect results.
  627.  
  628.              If the expression does not depend on the loop induction variable,
  629.              then all iterations will execute on the same thread, and will not
  630.              benefit from parallel execution.
  631.  
  632.              sssscccchhhheeeeddddttttyyyyppppeeee ((((ttttyyyyppppeeee))))
  633.  
  634.              Tells the multiprocessing C compiler how to share the loop
  635.              iterations among the processors. The schedtype chosen depends on
  636.              the type of system you are using and the number of programs
  637.              executing.  You can use the following valid types to modify
  638.              schedtype:
  639.  
  640.                  ssssiiiimmmmpppplllleeee (the default)
  641.  
  642.                  tells the run time scheduler to partition the iterations
  643.                  evenly among all the available threads.
  644.  
  645.                  rrrruuuunnnnttttiiiimmmmeeee
  646.  
  647.                  Tells the compiler that the real schedule type will be
  648.                  specified at run time.
  649.  
  650.                  ddddyyyynnnnaaaammmmiiiicccc
  651.  
  652.                  Tells the run time scheduler to give each thread chunksize
  653.                  iterations of the loop. chunksize should be smaller than
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  665.  
  666.  
  667.  
  668.                  (number of total iterations)/(number of threads). The
  669.                  advantage of dynamic over simple is that dynamic helps
  670.                  distribute the work more evenly than simple.
  671.  
  672.                  Depending on the data, some iterations of a loop can take
  673.                  longer to compute than others, so some threads may finish
  674.                  long before the others.  In this situation, if the iterations
  675.                  are distributed by simple, then the thread waits for the
  676.                  others. But if the iterations are distributed by dynamic, the
  677.                  thread doesn't wait, but goes back to get another chunksize
  678.                  iteration until the threads of execution have run all the
  679.                  iterations of the loop.
  680.  
  681.                  iiiinnnntttteeeerrrrlllleeeeaaaavvvveeee
  682.  
  683.                  Tells the run time scheduler to give each thread chunksize
  684.                  iterations (described below) of the loop, which are then
  685.                  assigned to the threads in an interleaved way.
  686.  
  687.                  ggggssssssss ((((gggguuuuiiiiddddeeeedddd sssseeeellllffff----sssscccchhhheeeedddduuuulllliiiinnnngggg))))
  688.  
  689.                  Tells the run time scheduler to give each processor a varied
  690.                  number of iterations of the loop. This is like dynamic, but
  691.                  instead of a fixed chunksize, the chunk size iterations begin
  692.                  with big pieces and end with small pieces.
  693.  
  694.                  If I iterations remain and P threads are working on them, the
  695.                  piece size is roughly:  I/(2P) + 1
  696.  
  697.                  Programs with triangular matrices should use gss.
  698.  
  699.                  cccchhhhuuuunnnnkkkkssssiiiizzzzeeee ((((eeeexxxxpppprrrr))))
  700.  
  701.                  Tells the multiprocessing C/C++ compiler how many iterations
  702.                  to define as a chunk when you use the dynamic or interleave
  703.                  modifier (described above).
  704.  
  705.                  eeeexxxxpppprrrr should be positive integer, and should evaluate to the
  706.                  following formula:
  707.  
  708.                       number of iterations / X
  709.  
  710.                  where _X is between twice and ten times the number of threads.
  711.                  Select twice the number of threads when iterations vary
  712.                  slightly. Reduce the chunk size to reflect the increasing
  713.                  variance in the iterations.  Performance gains may diminish
  714.                  after increasing _X to ten times the number of threads.
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  731.  
  732.  
  733.  
  734.      ####pppprrrraaaaggggmmmmaaaa oooonnnneeee pppprrrroooocccceeeessssssssoooorrrr
  735.  
  736.          A ####pppprrrraaaaggggmmmmaaaa oooonnnneeee pppprrrroooocccceeeessssssssoooorrrr directive causes the statement that follows
  737.          it to be executed by exactly one thread.
  738.  
  739.          The syntax of this pragma is:
  740.  
  741.          #pragma one processor
  742.  
  743.          { code }
  744.  
  745.  
  746.      ####pppprrrraaaaggggmmmmaaaa ccccrrrriiiittttiiiiccccaaaallll
  747.  
  748.          Sometimes the bulk of the work done by a loop can be done in
  749.          parallel, but the entire loop cannot run in parallel because of a
  750.          single data-dependent statement. Often, you can move such a statement
  751.          out of the parallel region.  When that is not possible, you can
  752.          sometimes use a lock on the statement to preserve the integrity of
  753.          the data.
  754.  
  755.          In the multiprocessing C/C++ compiler, use the critical pragma to put
  756.          a lock on a critical statement (or compound statement using { }).
  757.          When you put a lock on a statement, only one thread at a time can
  758.          execute that statement.  If one thread is already working on a
  759.          critical protected statement, any other thread that wants to execute
  760.          that statement must wait until that thread has finished executing it.
  761.  
  762.          The syntax of the critical pragma is:
  763.  
  764.          #pragma critical (lock_variable)
  765.  
  766.          { code }
  767.  
  768.          The statement(s) after the critical pragma will be executed by all
  769.          threads, one at a time. The lock variable _l_o_c_k__v_a_r_i_a_b_l_e is an
  770.          optional integer variable that must be initialized to zero. The
  771.          parentheses are required. If you don't specify a lock variable, the
  772.          compiler automatically supplies one.  Multiple critical constructs
  773.          inside the same parallel region are considered to be independent of
  774.          each other unless they use the same explicit lock variable.
  775.  
  776.  
  777.      ####pppprrrraaaaggggmmmmaaaa iiiinnnnddddeeeeppppeeeennnnddddeeeennnntttt
  778.  
  779.          Running a loop in parallel is a class of parallelism sometimes called
  780.          _f_i_n_e-_g_r_a_i_n_e_d _p_a_r_a_l_l_e_l_i_s_m or _h_o_m_o_g_e_n_e_o_u_s _p_a_r_a_l_l_e_l_i_s_m. It is called
  781.          homogeneous because all the threads execute the same code on
  782.          different data.  Another class of parallelism is called _c_o_a_r_s_e-
  783.          _g_r_a_i_n_e_d _p_a_r_a_l_l_e_l_i_s_m or _h_e_t_e_r_o_g_e_n_e_o_u_s _p_a_r_a_l_l_e_l_i_s_m. As the name
  784.          suggests, the code in each thread of execution is different.
  785.  
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  797.  
  798.  
  799.  
  800.          Ensuring data independence for heterogeneous code executed in
  801.          parallel is not always as easy as it is for homogeneous code executed
  802.          in parallel.  (Ensuring data independence for homogeneous code is not
  803.          a trivial task.)
  804.  
  805.          The independent pragma has no modifiers. Use this pragma to tell the
  806.          multiprocessing C/C++ compiler to run code in parallel with the rest
  807.          of the code in the parallel region.
  808.  
  809.          The syntax for #pragma independent is:
  810.  
  811.          #pragma independent
  812.  
  813.          { code }
  814.  
  815.  
  816.      SSSSyyyynnnncccchhhhrrrroooonnnniiiizzzzaaaattttiiiioooonnnn DDDDiiiirrrreeeeccccttttiiiivvvveeeessss
  817.  
  818.      To account for data dependencies, it is sometimes necessary for threads
  819.      to wait for all other threads to complete executing an earlier section of
  820.      code.  Two sets of directives implement this coordination: ####pppprrrraaaaggggmmmmaaaa
  821.      ssssyyyynnnncccchhhhrrrroooonnnniiiizzzzeeee and ####pppprrrraaaaggggmmmmaaaa eeeennnntttteeeerrrr////eeeexxxxiiiitttt ggggaaaatttteeee....
  822.  
  823.  
  824.      ####pppprrrraaaaggggmmmmaaaa ssssyyyynnnncccchhhhrrrroooonnnniiiizzzzeeee
  825.  
  826.           A ####pppprrrraaaaggggmmmmaaaa ssssyyyynnnncccchhhhrrrroooonnnniiiizzzzeeee tells the multiprocessing C/C++ compiler that
  827.           within a parallel region, no thread can execute the statements that
  828.           follows this pragma until all threads have reached it. This
  829.           directive is a classic barrier construct.
  830.  
  831.           The syntax for this pragma is:
  832.  
  833.           #pragma synchronize
  834.  
  835.  
  836.  
  837.      ####pppprrrraaaaggggmmmmaaaa eeeennnntttteeeerrrr ggggaaaatttteeee
  838.  
  839.           ####pppprrrraaaaggggmmmmaaaa eeeexxxxiiiitttt ggggaaaatttteeee
  840.  
  841.           You can use two additional pragmas to coordinate the processing of
  842.           code within a parallel region. These additional pragmas work as a
  843.           matched set.  They are ####pppprrrraaaaggggmmmmaaaa eeeennnntttteeeerrrr ggggaaaatttteeee and ####pppprrrraaaaggggmmmmaaaa eeeexxxxiiiitttt ggggaaaatttteeee....
  844.  
  845.           A gate is a special barrier. No thread can exit the gate until all
  846.           threads have entered it. This construct gives you more flexibility
  847.           when managing dependencies between the work-sharing constructs
  848.           within a parallel region.
  849.  
  850.           The syntax of the enter gate pragma is:
  851.  
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. MMMMPPPP((((3333CCCC))))                                                                  MMMMPPPP((((3333CCCC))))
  863.  
  864.  
  865.  
  866.           ####pppprrrraaaaggggmmmmaaaa eeeennnntttteeeerrrr ggggaaaatttteeee
  867.  
  868.           For example, construct D may be dependent on construct A, and
  869.           construct F may be dependent on construct B. However, you do not
  870.           want to stop at construct D because all the threads have not cleared
  871.           B. By using enter/exit gate pairs, you can make subtle distinctions
  872.           about which construct is dependent on which other construct.
  873.  
  874.           Put this pragma after the work-sharing construct that all threads
  875.           must clear before the ####pppprrrraaaaggggmmmmaaaa eeeexxxxiiiitttt ggggaaaatttteeee of the same name.
  876.  
  877.           The syntax of the exit gate pragma is:
  878.  
  879.           ####pppprrrraaaaggggmmmmaaaa eeeexxxxiiiitttt ggggaaaatttteeee
  880.  
  881.           Put this pragma before the work-sharing construct that is dependent
  882.           on the preceding ####pppprrrraaaaggggmmmmaaaa eeeennnntttteeeerrrr ggggaaaatttteeee.... No thread enters this work-
  883.           sharing construct until all threads have cleared the work-sharing
  884.           construct controlled by the corresponding ####pppprrrraaaaggggmmmmaaaa eeeennnntttteeeerrrr ggggaaaatttteeee....
  885.  
  886.  
  887.      ####pppprrrraaaaggggmmmmaaaa ppppaaaaggggeeee____ppppllllaaaacccceeee
  888.  
  889.           The syntax of this pragma is:
  890.  
  891.           #pragma page_place (addr, size, threadnum)
  892.  
  893.           where _a_d_d_r is the starting address, _s_i_z_e is the size in bytes, and
  894.           _t_h_r_e_a_d_n_u_m is the thread.
  895.  
  896.           On a system with physically distributed shared memory, for example,
  897.           Origin2000), you can explicitly place all data pages spanned by the
  898.           virtual address range [addr, addr + size-1] in the physical memory
  899.           of the processor corresponding to the specified thread.
  900.  
  901.  
  902. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  903.      cc(1), f77(1), mp(3f), sync(3c), sync(3f), _M_I_P_S_p_r_o _P_o_w_e_r _C _P_r_o_g_r_a_m_m_e_r'_s
  904.      _G_u_i_d_e, _M_I_P_S_p_r_o _C _L_a_n_g_u_a_g_e _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l, _M_I_P_S_p_r_o _F_O_R_T_R_A_N _7_7
  905.      _P_r_o_g_r_a_m_m_e_r'_s _G_u_i_d_e
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.                                                                        PPPPaaaaggggeeee 11114444
  922.  
  923.  
  924.  
  925.